import { ref } from 'vue';
const pickDay = ref();
const pickDay1 = ref();
const impose = ref(180);

export const calendarChangefunc = val => {
    const [pointDay, pointDay1] = val;
    pickDay.value = pointDay;
    pickDay1.value = pointDay1;
};

/**
 * 打开选择时间弹框时，恢复默认值
 */
export const visibleChange = () => {
    pickDay.value = '';
    pickDay1.value = '';
};

/**
 * 结束时间只能选择昨日及昨日之前的数据。默认为WTD的日期，选择范围180天
 */
export const disabledDateFunc = date => {
    const time = new Date(date).getTime();
    const currentTime = new Date().getTime() - 24 * 60 * 60 * 1000;
    if (time > currentTime) {
        return true;
    }
    if (!pickDay.value) {
        return false;
    }
    if (impose.value) {
        const con1 = new Date(pickDay.value).getTime() - impose.value * 24 * 60 * 60 * 1000;
        const con2 = new Date(pickDay.value).getTime() + impose.value * 24 * 60 * 60 * 1000;
        return time < con1 || time > con2;
    }
    return false;
};
